<?php if (!defined('THINK_PATH')) exit(); /*a:3:{s:59:"C:\xampp\htdocs\gyrjy/application/admin\view\nav\index.html";i:1534256479;s:61:"C:\xampp\htdocs\gyrjy/application/admin\view\nav\navtype.html";i:1534256479;s:57:"C:\xampp\htdocs\gyrjy/application/admin\view\nav\nav.html";i:1534256479;}*/ ?>
<?php $namespace = ns(); ?>
<div class="layout">
    <div class="layout-left" style="width: 20%;margin-right: -20%;">
        <div class="box" id="<?php echo $namespace; ?>type_box"></div>
    </div>
    <div class="layout-rightbox">
        <div class="layout-right" style="height:100%;overflow:auto;margin-left: 20%;">
            <div class="box" id="<?php echo $namespace; ?>_box"></div>
        </div>
    </div>
</div>

<script>
    Namespace.register("EBCMS.<?php echo $namespace; ?>type");
    $(function(){
        EBCMS.<?php echo $namespace; ?>type.refresh = function refresh(){
            EBCMS.CORE.api({
                queryParams:{
                    order:{
                        'sort':'desc',
                    },
                    model:'admin/navcate',
                },
                tree:true,
                treelevel:true,
                loadAfter:function(data){
                    EBCMS.CORE.compile({
                        data:data,
                        tpl:'<?php echo $namespace; ?>type-table',
                        target:'#<?php echo $namespace; ?>type_table',
                        compileAfter:function(p){
                            var $lists = $(p.target).find('a.list-group-item');
                            $lists.click(function(){
                                $lists.removeClass('active');
                                $(this).addClass('active');
                            });
                        }
                    });
                }
            });
        };
        EBCMS.<?php echo $namespace; ?>type.changecate = function changecate(category_id){
            EBCMS.<?php echo $namespace; ?>.category_id = category_id;
            EBCMS.CORE.compile({
                tpl:'<?php echo $namespace; ?>-box',
                target:'#<?php echo $namespace; ?>_box',
                compileAfter:function(){
                    EBCMS.<?php echo $namespace; ?>.refresh({
                        where:{
                            category_id:['eq',category_id],
                        }
                    });
                }
            });
        };
        EBCMS.CORE.compile({
            tpl:'<?php echo $namespace; ?>type-box',
            target:'#<?php echo $namespace; ?>type_box',
            compileAfter:function(){
                EBCMS.<?php echo $namespace; ?>type.refresh();
            }
        });
    });
</script>

<script id="<?php echo $namespace; ?>type-box" type="text/html">
    <div class="header">
        <div class="btn-group pull-right">
            <button class="btn btn-primary" onclick="EBCMS.CORE.changemain('<?php echo url('navcate/index'); ?>');">管理</button>
        </div>
        <div class="header-title" onclick="EBCMS.<?php echo $namespace; ?>type.refresh();">导航分类</div>
    </div>
    <div class="body" style="bottom:0px;">
        <div class="box" id="<?php echo $namespace; ?>type_table"></div>
    </div>
</script>

<script id="<?php echo $namespace; ?>type-table" type="text/html">
    <div class="list-group tree tree_first" style="border-top: 1px solid #ddd;border-right: 1px solid #ddd;border-bottom: 1px solid #ddd;">
        [[include '<?php echo $namespace; ?>type-table-item']]
    </div>
</script>

<script id="<?php echo $namespace; ?>type-table-item" type="text/html">
    [[each rows as v n]]
        [[if v.rows]]
            <a class="list-group-item" href="javascript:EBCMS.<?php echo $namespace; ?>type.changecate('[[v.id]]');">[[v.title]]
            </a>
            <div class="list-group-item nopadding">
                <div class="list-group tree nopadding">
                    [[include '<?php echo $namespace; ?>type-table-item' v]]
                </div>
            </div>
        [[else]]
            <a class="list-group-item" href="javascript:EBCMS.<?php echo $namespace; ?>type.changecate('[[v.id]]');"><span class="badge">[[v.mark]]</span>[[v.title]]
            </a>
        [[/if]]
    [[/each]]
</script>
<script>
    Namespace.register("EBCMS.<?php echo $namespace; ?>");
    $(function(){
        EBCMS.<?php echo $namespace; ?>.queryParams = {
            order:{
                'sort':'desc',
            },
            model:'admin/nav',
        };
        EBCMS.<?php echo $namespace; ?>.refresh = function refresh(p){
            if (p) {
                $.each(p, function(index, val) {
                    if (typeof val == 'object') {
                        EBCMS.<?php echo $namespace; ?>.queryParams[index] = $.extend(EBCMS.<?php echo $namespace; ?>.queryParams[index], p[index]);
                        delete p[index];
                    };
                });
                $.extend(EBCMS.<?php echo $namespace; ?>.queryParams, p);
            };
            EBCMS.CORE.api({
                queryParams:EBCMS.<?php echo $namespace; ?>.queryParams,
                tree:true,
                treelevel:true,
                tpl:'<?php echo $namespace; ?>-table',
                target:'#<?php echo $namespace; ?>_table',
                compileAfter:function(p){
                    $('#<?php echo $namespace; ?>_table').find('.input_sort').focus(function(){
                        EBCMS.<?php echo $namespace; ?>.sortvalue = $(this).val();
                    }).blur(function(){
                        var $this = $(this);
                        if ($this.val() != EBCMS.<?php echo $namespace; ?>.sortvalue) {
                            EBCMS.ACT.togglefield('<?php echo url('admin/nav/resort'); ?>',$this.data('id'),$this.val(),'<?php echo $namespace; ?>','resort');
                        };
                    });
                    $('#<?php echo $namespace; ?>_table').find('tr').bind('click', function(event) {
                        $(this).addClass('warning').siblings('tr').removeClass('warning');
                    });
                    EBCMS.FN.renderFilter({
                        namespace:'<?php echo $namespace; ?>',
                        filter:{
                            search:{
                                field:'group|title|url',
                                value:''
                            },
                            status:{
                                field:'status',
                            },
                            order:{
                                filters:{id:'id',update_time:'更新时间',sort:'权重'}
                            },
                        }
                    });
                },
            });
        };
        EBCMS.<?php echo $namespace; ?>.edit = function edit(id){
            EBCMS.CORE.get({
                url:'<?php echo url('admin/nav/edit'); ?>',
                queryParams:{
                    id:id,
                },
                target:'#lgModal .modal-content',
            });
        };
        EBCMS.<?php echo $namespace; ?>.add = function add(){
            if (EBCMS.<?php echo $namespace; ?>.category_id) {
                EBCMS.CORE.get({
                    url:'<?php echo url('admin/nav/add'); ?>',
                    queryParams:{
                        category_id:EBCMS.<?php echo $namespace; ?>.category_id,
                    },
                    target:'#lgModal .modal-content',
                });
            }else{
                EBCMS.MSG.notice('请先选择分类！');
            };
        };
    });
</script>

<script id="<?php echo $namespace; ?>-box" type="text/html">
    <div class="header">
        <div class="footer-page" id="<?php echo $namespace; ?>_filter"></div>
        <div class="header-title" onclick="EBCMS.<?php echo $namespace; ?>.refresh();">导航管理</div>
        <div class="btn-group">
            <button class="btn btn-primary" onclick="EBCMS.<?php echo $namespace; ?>.add();">添加</button>
        </div>
    </div>
    <div class="body" style="bottom:0px;">
        <div class="box" id="<?php echo $namespace; ?>_table"></div>
    </div> <button onclick=""></button>
</script>

<script id="<?php echo $namespace; ?>-table" type="text/html">
    <table class="table table-bordered table-hover table-ebcms">
        <tbody>
            <tr>
                <!-- <th style="width:70px;">id</th> -->
                <th style="width:200px;">操作</th>
                <th>名称</th>
                <th>连接</th>
                <th>排序</th>
            </tr>
            [[include '<?php echo $namespace; ?>-table-item']]
        </tbody>
    </table>
</script>

<script id="<?php echo $namespace; ?>-table-item" type="text/html">
    [[each rows as v n]]
        <tr>
            <!-- <td>[[v.id]]</td> -->
            <td>
                <div class="btn-group btn-group-sm">
                [[if v.status==1]]
                <button class="btn btn-primary" onclick="EBCMS.ACT.status('<?php echo url('admin/nav/status'); ?>','[[v.id]]','0','<?php echo $namespace; ?>');">已审</button>
                [[else]]
                <button class="btn btn-warning" onclick="EBCMS.ACT.status('<?php echo url('admin/nav/status'); ?>','[[v.id]]','1','<?php echo $namespace; ?>');">未审</button>
                [[/if]]
                <button class="btn btn-primary" onclick="EBCMS.<?php echo $namespace; ?>.edit('[[v.id]]');">编辑</button>
                <button class="btn btn-primary" onclick="EBCMS.ACT.del('<?php echo url('admin/nav/delete'); ?>','[[v.id]]','<?php echo $namespace; ?>');">删除</button>
                </div>
            </td>
            <td>[[v.levelstr]]┣[[v.title]]</td>
            <td>[[v.ebcms_url]]</td>
            <td><input value="[[v.sort]]" class="form-control input-sm input_sort" data-id="[[v.id]]"></td>
        </tr>
        [[if v.rows]]
            [[include '<?php echo $namespace; ?>-table-item' v]]
        [[/if]]
    [[/each]]
</script>